/*
 * @Author: your name
 * @Date: 2024-04-03 20:17:08
 * @LastEditTime: 2024-04-03 20:42:10
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \undefinedc:\Users\ljg\.leetcode\49.字母异位词分组.cpp
 */
/*
 * @lc app=leetcode.cn id=49 lang=cpp
 *
 * [49] 字母异位词分组
 */

// @lc code=start
class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        unordered_map<string, vector<string>> map;
        for(string str:strs){
            string key = str;
            sort(key.begin(), key.end());
            map[key].push_back(str);
        }
        vector<vector<string>> res;
        for(auto tmp:map){
            res.push_back(tmp.second);
        }
        return res;
    }
};
// @lc code=end
// 想不出来啊
// 方法就是对str进行排序，这样字母异位词的键就是一样的。
